package com.woniuxy.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserService userService;
	
	@RequestMapping("/login")
	@ResponseBody
	public ModelAndView login(User user,HttpServletRequest request) {
		HttpSession session=request.getSession();
		User loginuser=userService.login(user);
		ModelAndView mv =new ModelAndView();
		if (loginuser==null) {
			mv.setViewName("redirect:/login.html");
			return mv;
		}
		if (loginuser.getFlag()==0) {
			mv.setViewName("redirect:/manage.jsp");
			session.setAttribute("user", loginuser);
			return mv;
		}else {
			mv.setViewName("redirect:/userindex.jsp");
			session.setAttribute("user", loginuser);
			return mv;
		}
		
	}
}
